%% @doc Contains a function to parse binary messages from the game server. 
%% @end 
-module(parser).
-export([binmsg_to_tup/1]).


%Takes a binary message and returns: {atomic msg-type,[Arguments]}
%% @doc  Given a binary message it converts it to a tuple. It containis a atomic representing the message type and the messages arguments.  
%% @see  interface
%% @spec binmsg_to_tup(Bin) -> {atomic,[a]}
binmsg_to_tup(Bin) ->
	Msg   = binary_to_list(Bin),
    [T|M] = string:tokens(Msg, "|,"),
    case T of
		"1000"  -> {nullmessage,M};
		"1001"  -> {newchannel,M};
		"1002"  -> {members,M};
		"1003"  -> {channels,M};
		"1004"  -> {join,M};
		"1005"  -> {textmesg,M};
		"1006"  -> {leave,M};
		"1007"  -> {deletechannel,M};
		"1008"  -> {leaveall,M};
		"1009"  -> {putpiece,M};
		"1010"	-> {gametextmsg,M};
		"1011"	-> {leavegame,M};
		"1012"	-> {sitdown,M};
		"1013"	-> {joingame,M};
		"1014"  -> {boardlayout,M};
		"1015"	-> {deletegame,M};
		"1016"  -> {newgame,M};
		"1017"  -> {gamemembers,M};
		"1018"	-> {startgame,M};
		"1019"  -> {games,M};
		"1020"  -> {joinauth,M};
		"1021"  -> {joingameauth,M};
		"1022"  -> {imarobot,M};
		"1023"  -> {joingamerequest,M};
		"1024"  -> {playerelement,M};
		"1025"  -> {gamestate,M};
		"1026"  -> {turn,M};
		"1027"  -> {setupdone,M};
		"1028"  -> {diceresult,M};
		"1029"  -> {discardrequest,M};
		"1030"  -> {rolldicerequest,M};
		"1031"  -> {rolldiece,M};
		"1032"	-> {endturn,M};
		"1033"  -> {discard,M};
		"1034"  -> {moverobber,M};
		"1035"  -> {chooseplayer,M};
		"1036"  -> {chooseplayerrequest,M};
		"1037"  -> {rejectoffer,M};
		"1038"  -> {clearoffer,M};
		"1039"  -> {acceptoffer,M};
		"1040"  -> {banktrade,M};
		"1041"  -> {makeoffer,M};
		"1042"  -> {cleartrademsg,M};
		"1043"  -> {buildrequest,M};
		"1044"  -> {cancelbuildrequest,M};
		"1045"  -> {buycardrequest,M};
		"1046"  -> {devcard,M};
		"1047"  -> {devcardcount,M};
		"1048"  -> {setplayeddevcard,M};
		"1049"  -> {playdevcardrequest,M};
%borta	"1050"  -> {,M};
%borta	"1051"  -> {,M};
		"1052"  -> {discoverypick,M};
		"1053"  -> {monopolypick,M};
		"1054"  -> {firstplayer,M};
		"1055"  -> {setturn,M};
		"1056"  -> {robotdismiss,M};
		"1057"  -> {potentialsettlements,M};
		"1058"  -> {changeface,M};
		"1059"  -> {rejectconection,M};
		"1060"  -> {lastsettlement,M};
		"1061"  -> {gamestats,M};
		"1062"  -> {bcasttextmsg,M};
		"1063"  -> {resourcecount,M};
		"1064"  -> {adminping,M};
		"1065"  -> {adminreset,M};
		"1066"  -> {longestroad,M};
		"1067"  -> {largestarmy,M};
		"1068"  -> {setseatlock,M};
		"1069"  -> {statusmessage,M};
		"1070"  -> {createaccount,M};
		"1071"  -> {updaterobotparams,M};
		"1072"  -> {rolldicepromt,M};
		"1073"  -> {resetboardrequest,M};
		"1074"  -> {resetboardauth,M};
		"1075"  -> {resetboardvoterequest,M};
		"1076"  -> {resetboardvote,M};
		"1077"  -> {resetboardreject,M};
		"1078"  -> {newgamewithoptionsrequest,M};
		"1079"  -> {newgamewithoptions,M};
		"1080"  -> {gameoptiondefaults,M};
		"1081"  -> {gameoptiongetinfos,M};
		"1082"  -> {gameoptioninfo,M};
		"1083"  -> {gamewithoptions,M};
		"1084"  -> {boardlayout2,M};
		"1085"  -> {playerstats,M};
		"1086"  -> {playerelements,M};
		"1087"  -> {debugfreeplace,M};
		"9998"  -> {version,M};
		"9999"  -> {serverping,M};
		_Else   -> {unknown,M}
	end.
